var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function (err, conn) {

    if (err) {
        console.log(err);
        process.exit(0);
        return;
    }
    conn.createChannel(function (err, ch) {
        var ex = 'logs';
        var msg = process.argv.slice(2).join(' ') || 'Hello World';
    
        ch.assertExchange(ex, 'fanout', {durable: false});

        ch.publish(ex, '', new Buffer(msg));
        console.log(" [x] Sent %s", msg);
    });

    setTimeout(() => {
        conn.close();
        process.exit(0);
    }, 500);
});